FROM php:8.0-fpm

# 安装系统依赖
RUN apt-get update && apt-get install -y \
    git \
    curl \
    libpng-dev \
    libonig-dev \
    libxml2-dev \
    zip \
    unzip \
    libzip-dev

# 清理apt缓存
RUN apt-get clean && rm -rf /var/lib/apt/lists/*

# 安装PHP扩展
RUN docker-php-ext-install pdo_mysql mbstring exif pcntl bcmath gd zip

# 安装Composer
COPY --from=composer:latest /usr/bin/composer /usr/bin/composer

# 设置工作目录
WORKDIR /var/www

# 复制项目文件
COPY . /var/www

# 安装项目依赖
RUN composer install --no-dev --optimize-autoloader

# 设置目录权限
RUN chown -R www-data:www-data /var/www \
    && chmod -R 755 /var/www/runtime

# 修改php-fpm配置以监听9000端口
RUN echo "listen = 9000" >> /usr/local/etc/php-fpm.d/www.conf

CMD ["php-fpm"]
